// ChildToolBar.cpp : implementation file
//

#include "stdafx.h"
#include "ansieditor.h"
#include "ChildToolBar.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CChildToolBar

CChildToolBar::CChildToolBar()
{
}

CChildToolBar::~CChildToolBar()
{
}


BEGIN_MESSAGE_MAP(CChildToolBar, CToolBar)
	//{{AFX_MSG_MAP(CChildToolBar)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChildToolBar message handlers


BOOL CChildToolBar::SetStatusText(int nHit)
{
	CWnd* pOwner = gpFrame;// GetOwner();

	_AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
	if (nHit == -1)
	{
		// handle reset case
		pThreadState->m_pLastStatus = NULL;
		if (m_nStateFlags & statusSet)
		{
			pOwner->SendMessage(WM_POPMESSAGESTRING, AFX_IDS_IDLEMESSAGE);
			m_nStateFlags &= ~statusSet;
			return TRUE;
		}
		KillTimer(ID_TIMER_WAIT);
	}
	else
	{
		// handle setnew case
		if (!(m_nStateFlags & statusSet) || pThreadState->m_nLastStatus != nHit)
		{
			pThreadState->m_pLastStatus = this;
			pOwner->SendMessage(WM_SETMESSAGESTRING, nHit);
			m_nStateFlags |= statusSet;
			ResetTimer(ID_TIMER_CHECK, 200);
			return TRUE;
		}
	}
	return FALSE;
}

void CChildToolBar::SetColumns(int nColumns)
{
	int nCount = GetToolBarCtrl().GetButtonCount();

	if(nColumns == 0)
	{
		for(int i = 0; i < nCount; i++)
		{
			UINT nStyle = GetButtonStyle(i);
			nStyle &= ~TBBS_WRAPPED;
			SetButtonStyle(i, nStyle);
		}
	}
	else
	{
		for(int i = 0; i < nCount; i++)
		{
			UINT nStyle = GetButtonStyle(i);
			BOOL bWrap = (((i + 1) % nColumns) == 0);
			if (bWrap)
				nStyle |= TBBS_WRAPPED;
			else
				nStyle &= ~TBBS_WRAPPED;

			SetButtonStyle(i, nStyle);
		}
	}
}
